package com.jy.controller;

import com.jy.common.ResultInfo;
import com.jy.exception.CustomException;
import com.jy.service.IGetPlateNumberService;
import com.jy.vo.PlateJsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 提交车牌照片，并且拿到车牌号
 * @author Xiexingxie
 * @date 2022/11/15 下午 02:11
 */

@RestController
public class GetPlateNumberController {

    @Autowired
    private IGetPlateNumberService iGetPlateNumberService;

    @PostMapping("/upload-platenumber")
    @ResponseStatus(HttpStatus.CREATED)
    public PlateJsonResult plateJsonResult(MultipartFile multipartFile){
        String flag =iGetPlateNumberService.licensePlate(multipartFile);
        if (flag == null){
            throw new CustomException(20001, ResultInfo.PLATENUMBER_RECOGNITION_FAIL);
        }
        return PlateJsonResult.success(ResultInfo.PLATENUMBER_RECOGNITION_SUCCESS, flag);
    }

}
